INSERT INTO MATLABAnalytic VALUES('C:\...\SnC_G1_G6_MinMaxVectorPlots.dll', 'AustinG1G6', '', 1)
INSERT INTO MATLABAnalytic VALUES('C:\...\SnC_G2_IEEE_1668_Ridethrough.dll', 'Austin_G2_RideThrough', '', 2)
INSERT INTO MATLABAnalytic VALUES('C:\...\SnC_G3_FuseTCCcurve.dll', 'AustinG3', '', 3)
INSERT INTO MATLABAnalytic VALUES('C:\...\SnC_G5_Harmonics.dll', 'AustinG5_Harmonics', '', 4)
INSERT INTO MATLABAnalytic VALUES('C:\...\SnC_G7_Replay.dll', 'AustinG7', '', 5)
INSERT INTO MATLABAnalytic VALUES('C:\...\SEL_G7_Replay.dll', 'AustinG7', '', 6)
INSERT INTO MATLABAnalytic VALUES('C:\...\MakeReplay.dll', 'MakeReplay', '', 0)
GO

UPDATE MATLABAnalytic SET SettingSQL = 'SELECT
    COALESCE(Circuit.Name, Meter.Name) + ''-'' + Meter.Phasing + ''-'' + Meter.Orientation Station,
    Meter.Name Device,
    COALESCE(CONVERT(FLOAT, Setting.Value), 60.0) SystemFrequency,
    Event.Samples SampleCount,
    FORMAT(Event.StartTime, ''dd/MM/yyyy'') EventDate,
    FORMAT(Event.StartTime, ''HH:mm:ss.ffffff'') EventTime,
	COALESCE(SOE.ID, -1) AS SOE_ID,
    ''C:\...\classification.txt'' ClassificationsPath,
    RIGHT(DataFile.FilePath, CHARINDEX(''\'', REVERSE(DataFile.FilePath)) - 1) InputFilename,
    ''C:\...\Results\G1G6'' OutputFolder,
    CAST(CASE WHEN Meter.Make = ''SandC'' THEN 1 ELSE 0 END AS BIT) ExecuteAnalytic
FROM
    Event JOIN
    Meter ON Event.MeterID = Meter.ID LEFT OUTER JOIN
    Setting ON Setting.Name = ''SystemFrequency'' JOIN
    DataFile ON Event.FileGroupID = DataFile.FileGroupID LEFT OUTER JOIN
	Circuit ON Meter.CircuitID = Circuit.ID LEFT OUTER JOIN
    Incident ON Event.IncidentID = Incident.ID LEFT OUTER JOIN
    SOEIncident ON SOEIncident.IncidentID = Incident.ID LEFT OUTER JOIN
    SOE ON SOEIncident.SOEID = SOE.ID
WHERE Event.ID = {0}' WHERE MethodName = 'AustinG1G6'
GO

UPDATE MATLABAnalytic SET SettingSQL = 'SELECT
    COALESCE(Circuit.Name, Meter.Name) + ''-'' + Meter.Phasing + ''-'' + Meter.Orientation Station,
    Meter.Name Device,
    COALESCE(CONVERT(FLOAT, Setting.Value), 60.0) SystemFrequency,
    Event.Samples SampleCount,
    FORMAT(Event.StartTime, ''dd/MM/yyyy'') EventDate,
    FORMAT(Event.StartTime, ''HH:mm:ss.ffffff'') EventTime,
	COALESCE(SOE.ID, -1) AS SOE_ID,
    ''C:\...\classification.txt'' ClassificationsPath,
    RIGHT(DataFile.FilePath, CHARINDEX(''\'', REVERSE(DataFile.FilePath)) - 1) InputFilename,
    ''C:\...\Results\G2'' OutputFolder,
    CAST(CASE WHEN Meter.Make = ''SandC'' THEN 1 ELSE 0 END AS BIT) ExecuteAnalytic
FROM
    Event JOIN
    Meter ON Event.MeterID = Meter.ID LEFT OUTER JOIN
    Setting ON Setting.Name = ''SystemFrequency'' JOIN
    DataFile ON Event.FileGroupID = DataFile.FileGroupID LEFT OUTER JOIN
	Circuit ON Meter.CircuitID = Circuit.ID LEFT OUTER JOIN
    Incident ON Event.IncidentID = Incident.ID LEFT OUTER JOIN
    SOEIncident ON SOEIncident.IncidentID = Incident.ID LEFT OUTER JOIN
    SOE ON SOEIncident.SOEID = SOE.ID
WHERE Event.ID = {0}' WHERE MethodName = 'Austin_G2_RideThrough'
GO

UPDATE MATLABAnalytic SET SettingSQL = 'SELECT
    COALESCE(Circuit.Name, Meter.Name) + ''-'' + Meter.Phasing + ''-'' + Meter.Orientation Station,
    Meter.Name Device,
    COALESCE(CONVERT(FLOAT, Setting.Value), 60.0) SystemFrequency,
    Event.Samples SampleCount,
    FORMAT(Event.StartTime, ''dd/MM/yyyy'') EventDate,
    FORMAT(Event.StartTime, ''HH:mm:ss.ffffff'') EventTime,
	COALESCE(SOE.ID, -1) AS SOE_ID,
    ''C:\...\classification.txt'' ClassificationsPath,
    RIGHT(DataFile.FilePath, CHARINDEX(''\'', REVERSE(DataFile.FilePath)) - 1) InputFilename,
    ''C:\...\Results\G3'' OutputFolder,
    CAST(CASE WHEN Meter.Make = ''SandC'' THEN 1 ELSE 0 END AS BIT) ExecuteAnalytic
FROM
    Event JOIN
    Meter ON Event.MeterID = Meter.ID LEFT OUTER JOIN
    Setting ON Setting.Name = ''SystemFrequency'' JOIN
    DataFile ON Event.FileGroupID = DataFile.FileGroupID LEFT OUTER JOIN
	Circuit ON Meter.CircuitID = Circuit.ID LEFT OUTER JOIN
    Incident ON Event.IncidentID = Incident.ID LEFT OUTER JOIN
    SOEIncident ON SOEIncident.IncidentID = Incident.ID LEFT OUTER JOIN
    SOE ON SOEIncident.SOEID = SOE.ID
WHERE Event.ID = {0}' WHERE MethodName = 'AustinG3'
GO

UPDATE MATLABAnalytic SET SettingSQL = 'SELECT
    COALESCE(Circuit.Name, Meter.Name) + ''-'' + Meter.Phasing + ''-'' + Meter.Orientation Station,
    Meter.Name Device,
    COALESCE(CONVERT(FLOAT, Setting.Value), 60.0) SystemFrequency,
    Event.Samples SampleCount,
    FORMAT(Event.StartTime, ''dd/MM/yyyy'') EventDate,
    FORMAT(Event.StartTime, ''HH:mm:ss.ffffff'') EventTime,
	COALESCE(SOE.ID, -1) AS SOE_ID,
    ''C:\...\classification.txt'' ClassificationsPath,
    RIGHT(DataFile.FilePath, CHARINDEX(''\'', REVERSE(DataFile.FilePath)) - 1) InputFilename,
    ''C:\...\Results\G5'' OutputFolder,
    CAST(CASE WHEN Meter.Make = ''SandC'' THEN 1 ELSE 0 END AS BIT) ExecuteAnalytic
FROM
    Event JOIN
    Meter ON Event.MeterID = Meter.ID LEFT OUTER JOIN
    Setting ON Setting.Name = ''SystemFrequency'' JOIN
    DataFile ON Event.FileGroupID = DataFile.FileGroupID LEFT OUTER JOIN
	Circuit ON Meter.CircuitID = Circuit.ID LEFT OUTER JOIN
    Incident ON Event.IncidentID = Incident.ID LEFT OUTER JOIN
    SOEIncident ON SOEIncident.IncidentID = Incident.ID LEFT OUTER JOIN
    SOE ON SOEIncident.SOEID = SOE.ID
WHERE Event.ID = {0}' WHERE MethodName = 'AustinG5_Harmonics'
GO

UPDATE MATLABAnalytic SET SettingSQL = 'SELECT
    COALESCE(Circuit.Name, Meter.Name) + ''-'' + Meter.Phasing + ''-'' + Meter.Orientation Station,
    Meter.Name Device,
    COALESCE(CONVERT(FLOAT, Setting.Value), 60.0) SystemFrequency,
    Event.Samples SampleCount,
    FORMAT(Event.StartTime, ''dd/MM/yyyy'') EventDate,
    FORMAT(Event.StartTime, ''HH:mm:ss.ffffff'') EventTime,
	COALESCE(SOE.ID, -1) AS SOE_ID,
	COALESCE(FORMAT(SOE.StartTime, ''HH:mm:ss.ffffff''), FORMAT(GetDate(), ''HH:mm:ss.ffffff'')) as SOE_Time,
	Event.IncidentID as Incident_ID,
	Event.ID as Event_ID,
    ''C:\...\classification.txt'' ClassificationsPath,
    RIGHT(DataFile.FilePath, CHARINDEX(''\'', REVERSE(DataFile.FilePath)) - 1) InputFilename,
    ''C:\...\Results\G7'' OutputFolder,
    CAST(CASE WHEN Meter.Make = ''SandC'' THEN 1 ELSE 0 END AS BIT) ExecuteAnalytic
FROM
    Event JOIN
    Meter ON Event.MeterID = Meter.ID LEFT OUTER JOIN
    Setting ON Setting.Name = ''SystemFrequency'' JOIN
    DataFile ON Event.FileGroupID = DataFile.FileGroupID LEFT OUTER JOIN
	Circuit ON Meter.CircuitID = Circuit.ID LEFT OUTER JOIN
    Incident ON Event.IncidentID = Incident.ID LEFT OUTER JOIN
    SOEIncident ON SOEIncident.IncidentID = Incident.ID LEFT OUTER JOIN
    SOE ON SOEIncident.SOEID = SOE.ID
WHERE Event.ID = {0}' WHERE AssemblyName LIKE '%\Intellirupters\%' AND MethodName = 'AustinG7'
GO

UPDATE MATLABAnalytic SET SettingSQL = 'SELECT
    COALESCE(Circuit.Name, Meter.Name) + ''-'' + Meter.Phasing + ''-'' + Meter.Orientation Station,
    Meter.Name Device,
    COALESCE(CONVERT(FLOAT, Setting.Value), 60.0) SystemFrequency,
    Event.Samples SampleCount,
    FORMAT(Event.StartTime, ''dd/MM/yyyy'') EventDate,
    FORMAT(Event.StartTime, ''HH:mm:ss.ffffff'') EventTime,
	COALESCE(SOE.ID, -1) AS SOE_ID,
	COALESCE(FORMAT(SOE.StartTime, ''HH:mm:ss.ffffff''), FORMAT(GetDate(), ''HH:mm:ss.ffffff'')) as SOE_Time,
	Event.IncidentID as Incident_ID,
	Event.ID as Event_ID,
    ''C:\...\classification.txt'' ClassificationsPath,
    RIGHT(DataFile.FilePath, CHARINDEX(''\'', REVERSE(DataFile.FilePath)) - 1) InputFilename,
    ''C:\...\Results\G7'' OutputFolder,
    CAST(CASE WHEN Meter.Make = ''SEL'' THEN 1 ELSE 0 END AS BIT) ExecuteAnalytic
FROM
    Event JOIN
    Meter ON Event.MeterID = Meter.ID LEFT OUTER JOIN
    Setting ON Setting.Name = ''SystemFrequency'' JOIN
    DataFile ON Event.FileGroupID = DataFile.FileGroupID LEFT OUTER JOIN
	Circuit ON Meter.CircuitID = Circuit.ID LEFT OUTER JOIN
    Incident ON Event.IncidentID = Incident.ID LEFT OUTER JOIN
    SOEIncident ON SOEIncident.IncidentID = Incident.ID LEFT OUTER JOIN
    SOE ON SOEIncident.SOEID = SOE.ID
WHERE Event.ID = {0}' WHERE AssemblyName LIKE '%\SEL\%' AND MethodName = 'AustinG7'
GO